﻿using System;
using System.Linq;
using SuperSocket.Command;
using SuperSocket.ProtoBase;
using SuperSocketV2Sample.Service.Server;

namespace SuperSocketV2Sample.Service.Commands
{
    /// <summary>
    /// 减法命令
    /// </summary>
    [Command(Key = "SUB")]
    [AsyncKeyUpperCommandFilter]
    public class SubCommand : BaseCommand
    {
        protected override string GetResult(StringPackageInfo package)
        {
            string result;
            try
            {
                result = package.Parameters
                    // ReSharper disable once ConvertClosureToMethodGroup
                    .Select(t => int.Parse(t))
                    .Aggregate((x, y) => x - y)
                    .ToString();
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return result;
        }
    }
}
